package com.ruoyi.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.domain.entity.Comment;
import com.ruoyi.domain.vo.CommentVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommentMapper extends BaseMapper<Comment> {

    List<Integer> getLikeIds(@Param("userId") Integer userId, @Param("postId") Integer postId);


    List<CommentVo> getCommentList(@Param("postId") Integer postId, @Param("begin") Integer begin, @Param("pageSize") Integer pageSize);


    List<CommentVo> selectReplyList(@Param("postId") Integer postId, @Param("commentId") Integer commentId);

    @Select("select count(1) from comment_like where user_id = #{userId} and comment_id = #{commentId}")
    int getLikeCount(@Param("userId") Integer userId, @Param("commentId")Integer commentId);

    @Insert("insert into comment_like(user_id, comment_id) values(#{userId},#{commentId}) ")
    void likeComment(@Param("userId") Integer userId, @Param("commentId")Integer commentId);

    // 根据用户id和评论id删除对应的点赞记录，实现取消点赞操作
    @Delete("delete from comment_like where user_id = #{userId} and comment_id = #{commentId}")
    void cancelLikeComment(@Param("userId") Integer userId, @Param("commentId") Integer commentId);
}
